clear
set mem 800m
use psid-2007, replace
sort ER36002
dmerge ER36002 using income-2007
tab _merge
drop _merge

gen temp="-"
egen uniqueid=concat(ER30001 temp ER30002)
drop temp

gen sample=1 if ER32000==2
replace sample=0 if ER33904<15 | ER33904>44
replace sample=0 if ER33901==0

gen hohin07=ER36002

gen births_2007=1 if ER32024==2007 | ER32024==2006
replace births_2007=1 if ER32026==2007 | ER32026==2006
replace births_2007=1 if ER32028==2007 | ER32028==2006
replace births_2007=1 if ER32030==2007 | ER32030==2006
replace births_2007=1 if ER32032==2007 | ER32032==2006
replace births_2007=0 if births_2007==.

gen age=ER33904

gen married=ER32049==1

gen fuchildren_lag0=ER36020
replace fuchildren_lag0=fuchildren_lag0-1 if births_2007==1
drop if fu<0

gen housevalue_lag0=ER36029
gen housevalue_lag2=ER25029
gen housevalue_lag4=ER21043

gen educ=ER33917

gen tot_fam_y_lag0=ER41027

keep if sample==1

gen year=07

gen state_2007=ER36003

gen fips07=1 if state_2007==1
replace fips07=2 if state_2007==50
replace fips07=4 if state_2007==2
replace fips07=5 if state_2007==3
replace fips07=6 if state_2007==4
replace fips07=8 if state_2007==5
replace fips07=9 if state_2007==6
replace fips07=10 if state_2007==7
replace fips07=11 if state_2007==8
replace fips07=12 if state_2007==9
replace fips07=13 if state_2007==10
replace fips07=15 if state_2007==51
replace fips07=16 if state_2007==11
replace fips07=17 if state_2007==12
replace fips07=18 if state_2007==13
replace fips07=19 if state_2007==14
replace fips07=20 if state_2007==15
replace fips07=21 if state_2007==16
replace fips07=22 if state_2007==17
replace fips07=23 if state_2007==18
replace fips07=24 if state_2007==19
replace fips07=25 if state_2007==20
replace fips07=26 if state_2007==21
replace fips07=27 if state_2007==22
replace fips07=28 if state_2007==23
replace fips07=29 if state_2007==24
replace fips07=30 if state_2007==25
replace fips07=31 if state_2007==26
replace fips07=32 if state_2007==27
replace fips07=33 if state_2007==28
replace fips07=34 if state_2007==29
replace fips07=35 if state_2007==30
replace fips07=36 if state_2007==31
replace fips07=37 if state_2007==32
replace fips07=38 if state_2007==33
replace fips07=39 if state_2007==34
replace fips07=40 if state_2007==35
replace fips07=41 if state_2007==36
replace fips07=42 if state_2007==37
replace fips07=44 if state_2007==38
replace fips07=45 if state_2007==39
replace fips07=46 if state_2007==40
replace fips07=47 if state_2007==41
replace fips07=48 if state_2007==42
replace fips07=49 if state_2007==43
replace fips07=50 if state_2007==44
replace fips07=51 if state_2007==45
replace fips07=53 if state_2007==46
replace fips07=54 if state_2007==47
replace fips07=55 if state_2007==48
replace fips07=56 if state_2007==49

keep hohin07 births_2007 age married fuchildren_lag0 housevalue_lag0 housevalue_lag2 housevalue_lag4 educ tot_fam_y_lag0 year ER36002 fips07 uniqueid

